package com.xxxy.jsq.action.type;

import com.alibaba.fastjson2.JSONObject;

import com.xxxy.jsq.dao.TypeDao;
import com.xxxy.jsq.model.Type;


import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
//
@WebServlet("/getTypeServlet")
public class getTypeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public getTypeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        TypeDao dao=new TypeDao();//s数据库访问

        List<Type> list=dao.getAllky();
        System.out.println(list);//从控制台输出日志
        JSONObject jo=new JSONObject();//建立Json对象
        //构建Json对象
        //jo.put("code", 0);
        //jo.put("msg", "你好");
        //jo.put("count", total);
        jo.put("data", list);
        System.out.println(jo.toString());
        PrintWriter out=response.getWriter();
        out.print(jo);
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
